#include "UserSettings.h"

namespace util {

UserSettings& UserSettings::getInstance() {
    static UserSettings INSTANCE;
    return INSTANCE;
}

void setDirs(fs::path _measurementFolder,
             fs::path _dataDir, fs::path _cfgDir,
             fs::path _moDir) {

    UserSettings& us = UserSettings::getInstance();

    us.measurementFolder = _measurementFolder;
    us.dataDir = _dataDir;
    us.cfgDir = _cfgDir;
    us.moDir = _moDir;
}

void setDir(enum DataDirectories dir, fs::path p) {
    UserSettings& us = UserSettings::getInstance();

    switch(dir) {
    case MeasDir:   us.measurementFolder = p;
                    us.dataDir = p / "data";
                    us.cfgDir = p / "cfg";
                    us.moDir = p / "mos";
                    break;
    case DataDir:   us.dataDir = p;
                    break;
    case CfgDir :   us.cfgDir = p;
                    break;
    case MoDir  :   us.moDir = p;
                    break;
    default     :   throw (boost::format("Cannot set dir: %1%") % dir).str();
    }
}

void setDir(enum DataDirectories dir, std::wstring p) {
    setDir(dir, fs::path(p));
}

fs::path getDir(enum DataDirectories dir) {
    UserSettings& us = UserSettings::getInstance();

    switch(dir) {
    case MeasDir: return us.measurementFolder;
    case DataDir: return us.dataDir;
    case CfgDir : return us.cfgDir;
    case MoDir  : return us.moDir;
    default     : throw (boost::format("Invalid dir request: %1%") % dir).str();
    }
}

std::string getDirAsString(enum DataDirectories dir) {
    try {
        fs::path p = getDir(dir);
        return p.string();
    } catch(std::string& err) {
        throw err;
    }
}

}
